package com.example.home.film;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.film.bean.FilmDetailBean;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class FilmDetailActivity extends AppCompatActivity {

    private ImageView back;
    private TextView title;
    private ImageView imgUrl;
    private TextView name;
    private TextView score;
    private TextView playDate;
    private TextView likeNum;
    private Button backMain;
    private String filmId;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_film_detail);

        Intent intent = getIntent();
        filmId = intent.getStringExtra("filmId");


        initView();

        getDetailList();
    }

    private void getDetailList() {
        OKHttpTool.doNetRequest("prod-api/api/movie/film/detail/"+filmId,
                OKHttpTool.GET,
                FilmDetailBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        FilmDetailBean filmDetailBean = (FilmDetailBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                FilmDetailBean.DataBean data = filmDetailBean.getData();
                                Glide.with(FilmDetailActivity.this).load(ip+data.getCover()).into(imgUrl);
                                title.setText(data.getName());
                                name.setText("电影："+data.getName());
                                score.setText("评分："+data.getScore()+"分");
                                playDate.setText("上映时间："+data.getPlayDate());
                                likeNum.setText("想看人数："+data.getLikeNum());
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void initView() {

        back = findViewById(R.id.back);
        title = findViewById(R.id.title);
        imgUrl = findViewById(R.id.imgUrl);
        name = findViewById(R.id.name);
        score = findViewById(R.id.score);
        playDate = findViewById(R.id.playDate);
        likeNum = findViewById(R.id.likeNum);
        backMain = findViewById(R.id.back_main);

        back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FilmDetailActivity.this.finish();
            }
        });

        backMain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                FilmDetailActivity.this.finish();
            }
        });
    }
}